﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

public class Verb_AlwaysSelf : Verb_LaunchProjectile//这个要改成飞瞄准式单一的，明天改
{


    public override bool CanHitTarget(LocalTargetInfo targ)
    {
        return true;
    }

    public override bool TryStartCastOn(LocalTargetInfo castTarg, LocalTargetInfo destTarg, bool surpriseAttack = false, bool canHitNonTargetPawns = true, bool preventFriendlyFire = false, bool nonInterruptingSelfCast = false)
    {
        if (caster == null)
        {
            Log.Error("Verb " + GetUniqueLoadID() + " needs caster to work (possibly lost during saving/loading).");
            return false;
        }
        if (state == VerbState.Bursting)
        {
            return false;
        }
        this.surpriseAttack = surpriseAttack;
        canHitNonTargetPawnsNow = canHitNonTargetPawns;
        this.preventFriendlyFire = preventFriendlyFire;
        this.nonInterruptingSelfCast = nonInterruptingSelfCast;
        currentTarget = castTarg;
        currentDestination = destTarg;

        if (CasterIsPawn && verbProps.warmupTime > 0f)
        {
            float statValue = CasterPawn.GetStatValue(StatDefOf.AimingDelayFactor);
            int ticks = (verbProps.warmupTime * statValue).SecondsToTicks();
            CasterPawn.stances.SetStance(new Stance_Warmup(ticks, castTarg, this));
            if (verbProps.stunTargetOnCastStart && castTarg.Pawn != null)
            {
                castTarg.Pawn.stances.stunner.StunFor(ticks, null, addBattleLog: false);
            }
        }
        else
        {
            WarmupComplete();
        }
        return true;
    }
    protected override bool TryCastShot()
    {
        ThingDef projectile = Projectile;
        Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile,this.Caster.Position, caster.Map);

        Thing manningPawn = caster;
        Vector3 drawPos = caster.DrawPos;
        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.All;
        Thing equipmentSource = base.EquipmentSource;
        projectile2.Launch(manningPawn, drawPos, currentTarget, currentTarget, projectileHitFlags, preventFriendlyFire, equipmentSource);
        return true;

    }

}

